package com.example.mrzhou.srtfoodapplication;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by SRTfood on 2017/1/21.
 */

public class CategoryActivity extends BaseActivity {


    private List<Fresh> freshList = new ArrayList<Fresh>();
    private int a,b,c;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.category_layout);
        initFresh();
        FreshAdapter adapter = new FreshAdapter(CategoryActivity.this,
                R.layout.fresh_item,freshList);
        ListView listView = (ListView) findViewById(R.id.list_view);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Fresh fresh = freshList.get(position);
                if (fresh.getFreshTitle()=="限时打折") {
                    a=R.drawable.fresh_a;b=R.drawable.fresh_time_2;c=R.drawable.fresh_time_3;
                }
                if (fresh.getFreshTitle()=="区域特色") {
                    a=R.drawable.fresh_b;b=R.drawable.fresh_here_2;c=R.drawable.fresh_here_3;
                }
                if (fresh.getFreshTitle()=="地区热门") {
                    a=R.drawable.fresh_c;b=R.drawable.fresh_hot_2;c=R.drawable.fresh_hot_3;
                }
                CategoryClassActivity.actionStart(CategoryActivity.this, fresh.getFreshTitle(), a, b, c);
            }
        });
    }

    private void initFresh() {
        Fresh fresh1 = new Fresh();
        fresh1.setFreshImage(R.drawable.fresh_a);
        fresh1.setFreshName("  · 限时打折");
        fresh1.setFreshTitle("限时打折");
        freshList.add(fresh1);
        Fresh fresh2 = new Fresh();
        fresh2.setFreshImage(R.drawable.fresh_b);
        fresh2.setFreshName("  · 区域特色");
        fresh2.setFreshTitle("区域特色");
        freshList.add(fresh2);
        Fresh fresh3 = new Fresh();
        fresh3.setFreshImage(R.drawable.fresh_c);
        fresh3.setFreshName("  · 地区热门");
        fresh3.setFreshTitle("地区热门");
        freshList.add(fresh3);
    }
}
